package com.xjtu.weixin.controller.user;

import com.xjtu.weixin.model.entity.MpUser;
import com.xjtu.weixin.service.MpUserService;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.result.WxMpUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * ${DESCRIPTION}
 *
 * @author 杨凯
 * @create 2018-08-21 14:45
 **/
@Controller
@RequestMapping("/user")
@Slf4j
public class UserController {

	@Autowired
	private MpUserService userService;

	@Autowired
	private WxMpService wxMpService;

	@GetMapping
	public String index(Model model) {
		//TODO 只对数据进行展示，未分页
		final List<MpUser> mpUsers = userService.selectUserList();
		model.addAttribute("mpUsers", mpUsers);
		return "admin/user/user-list";
	}


	/**
	 * 修改用户备注
	 * @param openId
	 * @param remark
	 * @return
	 */
	@PostMapping("/update_remark")
	@ResponseBody
	public ResponseEntity updateRemark(@RequestParam String openId,@RequestParam String remark) throws WxErrorException {
		userService.updateUserRemark(openId,remark);
		return new ResponseEntity("修改成功!",HttpStatus.OK);
	}


	/**
	 * 移除用户
	 * @param openId
	 * @return
	 */
	public ResponseEntity removeUser(@RequestParam String openId){
		return new ResponseEntity("移除成功!",HttpStatus.OK);
	}
}
